package com.oss.web;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author xueqiang.mi
 * @since 2010-7-14
 */
@Controller
public class RobotController extends BaseController {

	@RequestMapping("/robot/classfyLinks.do")
	public String classfyLinks() {
		classfyRobot.doClassfy();
		return "robot/result";
	}

	@RequestMapping(value = "/robot/normalizePrjsByTag.do", method = RequestMethod.GET)
	public String enablePrjs(@RequestParam("id") String id) {
		prjService.normalizePrjsByTag(id);
		return "robot/result";
	}

	@RequestMapping(value = "/robot/extractSite.do", method = RequestMethod.GET)
	public String extractSite(
			@RequestParam(value = "pageIndex", required = false) Long pageIndex,
			@RequestParam(value = "pageSize", required = false) Long pageSize) {
		pageIndex = (pageIndex != null) ? pageIndex : 1;
		pageSize = (pageSize != null) ? pageSize : 100;
		siteRobot.extract(pageIndex, pageSize);
		return "robot/result";
	}

	@RequestMapping(value = "/robot/getLinksFromDZone.do", method = RequestMethod.GET)
	public String getLinksFromDZone() {
		dzoneRobot.retrieveData();
		return "robot/result";
	}

	@RequestMapping(value = "/robot/getLinksFromInfoQ.do", method = RequestMethod.GET)
	public String getLinksFromInfoQ() {
		infoQRobot.retrieveData();
		return "robot/result";
	}

	@RequestMapping(value = "/robot/getLinksFromJavaWorld.do", method = RequestMethod.GET)
	public String getLinksFromJavaWorld() {
		javaWorldRobot.retrieveData();
		return "robot/result";
	}

	@RequestMapping(value = "/robot/getLinksFromTSS.do", method = RequestMethod.GET)
	public String getLinksFromTSS() {
		tssRobot.retrieveData();
		return "robot/result";
	}

	@RequestMapping(value = "/robot/getPrjsFromApache.do", method = RequestMethod.GET)
	public String getPrjsFromApache() throws Exception {
		apacheRobot.retrieveProjects();
		return "robot/result";
	}

	@RequestMapping(value = "/robot/getPrjsFromJBoss.do", method = RequestMethod.GET)
	public String getPrjsFromJBoss() throws Exception {
		jbossRobot.retrieveProjects();
		return "robot/result";
	}

	@RequestMapping(value = "/robot/getPrjsFromMOS.do", method = RequestMethod.GET)
	public String getPrjsFromMOS() throws Exception {
		muleSoftRobot.retrieveProjects();
		openSymphonyRobot.retrieveProjects();
		springSourceRobot.retrieveProjects();
		return "robot/result";
	}

	@RequestMapping(value = "/robot/prepareTasksFromDZone.do", method = RequestMethod.GET)
	public String prepareTasksFromDZone() {
		dzoneRobot.prepareTasks();
		return "robot/result";
	}

	@RequestMapping(value = "/robot/prepareTasksFromJavaWorld.do", method = RequestMethod.GET)
	public String prepareTasksFromJavaWorld() {
		javaWorldRobot.prepareTasks();
		return "robot/result";
	}

	@RequestMapping(value = "/robot/prepareTasksFromTSS.do", method = RequestMethod.GET)
	public String prepareTasksFromTSS() {
		tssRobot.prepareTasks();
		return "robot/result";
	}

	@RequestMapping(value = "/robot/retrieveUrlsFromApache.do", method = RequestMethod.GET)
	public String retrieveUrlsFromApache() throws Exception {
		apacheRobot.retrieveUrls();
		return "robot/result";
	}

	@RequestMapping(value = "/robot/stat.do", method = RequestMethod.GET)
	public String stat(
			@RequestParam(value = "pageIndex", required = false) Long pageIndex,
			@RequestParam(value = "pageSize", required = false) Long pageSize) {
		pageIndex = (pageIndex != null) ? pageIndex : 1;
		pageSize = (pageSize != null) ? pageSize : 100;
		statRobot.statQuantity(pageIndex, pageSize);
		return "robot/result";
	}

}
